<template>
  <Layout>
    <div style="min-height: 600px">
      <el-card shadow="never" style="min-height: 400px" v-if="post.id">
        <div slot="header">
          <span>{{ post.title }}</span>
        </div>
        <div style="font-size: 0.9rem; line-height: 1.5; color: #606c71">
          发布 {{ post.created_at }} <br />
          更新 {{ post.updated_at }}
        </div>
        <div
          style="
            font-size: 1.1rem;
            line-height: 1.5;
            color: #303133;
            border-bottom: 1px solid #e4e7ed;
            padding: 5px 0px 5px 0px;
          "
        >
          <!-- <pre style="font-family: '微软雅黑'">{{ post.description }}</pre> -->
        </div>
        <div
          v-html="post.content"
          class="markdown-body"
          style="padding-top: 20px"
        ></div>
        <p>
          <span
            v-for="tag in post.tags"
            :key="tag.id">
            {{ tag.title }}
          </span>
        </p>
      </el-card>
      <el-card
        shadow="never"
        style="
          margin-bottom: 20px;
          padding: 20px 0px 20px 0px;
          text-align: center;
        "
        v-if="!post.id"
      >
        <font style="font-size: 30px; color: #dddddd">
          <b>没有更新 ╮(๑•́ ₃•̀๑)╭</b>
        </font>
      </el-card>
    </div>
  </Layout>
</template>

<page-query>
query {
  posts: allStrapiPost {
    edges {
      node {
        id
        title
        content
        user
      	tags {
          id
          title
        }
        created_at
        updated_at
      }
    }
  }
}
</page-query>

<script>
export default {
  name: "NewPage",
  data() {
    return {
      post: {
        id: "",
        title: "",
        content: "",
        description: "",
        created_at: "",
        updated_at: "",
        tags: []
      }
    }
  },
  mounted() {
    const node = this.$page.posts.edges[0].node

    this.post['id'] = node['id']
    this.post['title'] = node['title']
    this.post['content'] = node['content']
    this.post['description'] = node['description']
    this.post['tags'] = node['tags']

    this.post['created_at'] = this.$util.utcToLocal(node['created_at'])
    this.post['updated_at'] = this.$util.utcToLocal(node['updated_at'])
  }
};
</script>

<style>
</style>
